<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>实现一个JS函数柯里化</title>
</head>
<body>
<script type="text/javascript">
function currying(fn, ...args) {
	let length = fn.length;//获取fn声明的参数个数
	let allArgs = [...args];
	const res = (...newArgs) => {
		allArgs = [...allArgs, ...newArgs];
		if(allArgs.length === length) {
			return fn(...allArgs);
		}else {
			return res;//如果参数长度未达标,保存参数后,继续返回函数
		}
	}

	return res;
}
</script>
<script type="text/javascript">
// 用法如下：
const add = (a, b, c) => a + b + c;
const a = currying(add, 4);
console.log(a(5));//输出的是函数
console.log(a(6))//参数达到3个,输出15
</script>
</body>
</html>